package com.bq.gametrade.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.bq.gametrade.R;
import com.bq.gametrade.base.BaseActivity;
import com.bq.gametrade.bean.UserInfoDetails;
import com.bq.gametrade.utils.NetworkUtils;

public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener{

    private ImageView back;
    private TextView tvTitle;
    private EditText originalPassword,newPassword,confirmPassword;
    private Button btnConfirm;
    private UserInfoDetails userInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_password);
        if(application.isLogin()){
            userInfo = application.getUserInfo();
        }else {
            startActivity(new Intent(this, LoginActivity.class));
            finish();
        }
        initView();
    }

    private void initView(){
        back = serchViewById(R.id.image_back);
        back.setOnClickListener(this);
        tvTitle = serchViewById(R.id.title_name);
        tvTitle.setText("修改密码");
        originalPassword = serchViewById(R.id.ed_originalPassword);
        newPassword = serchViewById(R.id.ed_newPassword);
        confirmPassword = serchViewById(R.id.ed_confirmPassword);
        btnConfirm = serchViewById(R.id.btn_confirm);
        btnConfirm.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.image_back:
                finish();
                break;
            case R.id.btn_confirm:
                if(TextUtils.isEmpty(originalPassword.getText().toString())){
                    toastShow("原密码未填写");
                    return;
                }
                if(TextUtils.isEmpty(newPassword.getText().toString())){
                    toastShow("新密码未填写");
                    return;
                }
                if(newPassword.getText().toString().length()<6){
                    toastShow("新密码不能少于6位");
                    return;
                }
                if(!confirmPassword.getText().toString().equals("newPassword.getText().toString()")){
                    toastShow("两次密码不一样");
                    return;
              }
                if(NetworkUtils.isNetworkAvailable(ChangePasswordActivity.this)){
                    toastShow("有网络可以进行请求");
                }else {
                    toastShow("请检查你的网络");
                }
                break;
        }
    }


}
